#include <windows.h>
#include <time.h>
#include <math.h>

#include <qhash.h>
#include <qpoint.h>
#include <qdebug.h>
#include <QtGui>
#include <QObject>
#include <QtGui/QApplication>

#include "mainwindow.h"
#include "classes\carvis.h"
#include "classes\Automat.hpp"
#include "classes\RoadCell.hpp"
#include "painThread.h"

int main(int argc, char *argv[])
{
	int wspolczynnik=10;
	QApplication a(argc, argv);
	qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));

	QGraphicsScene scene;

	scene.setSceneRect(10*wspolczynnik, 10*wspolczynnik, 40*10, 40*10);
	scene.setItemIndexMethod(QGraphicsScene::NoIndex);
	//QHash<int,QPoint> Entry_points = test.getEntryList();  // --> punkty startowe 
	Automat *test = new Automat();
	Carvis *autko = new Carvis(1);
	Carvis *autko2 = new Carvis(2);
	painThread watek(test,autko);
	scene.addItem(autko);
	scene.addItem(autko2);
   
	QObject::connect(&watek, SIGNAL(obliczono_ruch(QPoint, int)), autko, SLOT(zrob_ruch(QPoint,int)));
	QObject::connect(&watek, SIGNAL(obliczono_ruch(QPoint, int)), autko2, SLOT(zrob_ruch(QPoint,int)));
   
	watek.start();
	
	QGraphicsView view(&scene);
	view.setRenderHint(QPainter::Antialiasing);
	view.setBackgroundBrush(QPixmap("mapa/test.jpg"));
	view.setCacheMode(QGraphicsView::CacheBackground);
	view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
	view.setDragMode(QGraphicsView::ScrollHandDrag);
	view.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Traffic Simulator"));

	#if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR)
    view.showMaximized();
	#else
	view.showMaximized();
    view.show();
	#endif

	QTimer *timer = new QTimer();
	//timer->setInterval(30);
	//QObject::connect(timer, SIGNAL(timeout()), &scene, SLOT(advance()));
	//timer->start();

	
     
    return a.exec();
}
